<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="cn.ml.web3.entity.Student" %>
<%@ page import="cn.ml.web3.entity.Pagination" %>
<%@ page import="cn.ml.web3.dao.StudentDao" %>
<%@ page import="cn.ml.web3.dao.StudentDaoImpl" %>

<%@ page contentType="text/html;charset=UTF-8" %>
<%
    request.setCharacterEncoding("utf-8");
    //收集数据
    String likeName = request.getParameter("likeName");
    String gender = request.getParameter("gender");
    String start = request.getParameter("start");
    String end = request.getParameter("end");
    Map<String,String> params = new HashMap<String,String>();
    //trim()非空格
    if(likeName!=null && likeName.trim().length()>0){
        params.put("likeName",likeName);
    }
    if(gender!=null && (gender.equals("男") || gender.equals("女"))){
        params.put("gender",gender);
    }
    //d代表数字{4}是4位
    String dateregex="\\d{4}-\\d{2}-\\d{2}";
    if(start!=null && start.matches(dateregex)){
        params.put("start",start);
    }
    //end符合正则
    if(end!=null && end.matches(dateregex)){
        params.put("end",end);
    }
    String currentPageIndexStr = request.getParameter("currentPageIndex");
    int currentPageIndex = 1;
    if(currentPageIndexStr != null && currentPageIndexStr.matches("\\d+")){
        currentPageIndex = Integer.parseInt(currentPageIndexStr);
    }
    String pageSizeStr = request.getParameter("pageSize");
    int pageSize = 3;
    if(pageSizeStr != null && pageSizeStr.matches("\\d+")){
        pageSize = Integer.parseInt(pageSizeStr);
    }
    Pagination<Student> pagination = new Pagination<Student>();
    pagination.setCurrentPageIndex(currentPageIndex);
    pagination.setPageSize(pageSize);
    //查询
    StudentDao dao = new StudentDaoImpl();
    dao.listByPaginationAndParams(pagination,params);
    //转发
    request.setAttribute("pagination",pagination);
    request.getRequestDispatcher("listStudent.jsp").forward(request,response);

%>